import {defineStore} from "pinia";
import {ref} from "vue";

export const useUserInfoStore = defineStore('userInfo',
    () => {
    // 定义变量
      const userInfo = ref({
        username: '',
        role: '',
        // 其他字段
      });

        // 设置值
      const setUserInfo = (data) => {
        userInfo.value = {
          ...data,
          role: data.role || '',
        };
      }

      // 清理值
      const removeUserInfo = () => {
        userInfo.value = {}
      }

      return {
        userInfo, setUserInfo, removeUserInfo
      }
    },
    {
      persist: true  // 持久化
    });